Skip to content

fix: use monotonic clock for file processing timeout - #3748

Open
Hughhhhcoder wants to merge 1 commit into
openai:mainfrom
Hughhhhcoder:codex/openai-python-file-timeout
Open

fix: use monotonic clock for file processing timeout#3748
Hughhhhcoder wants to merge 1 commit into
openai:mainfrom
Hughhhhcoder:codex/openai-python-file-timeout

Conversation

@Hughhhhcoder

Copy link
Copy Markdown

Summary

  • Use time.monotonic() for elapsed-time deadlines in both synchronous and asynchronous file-processing polling.
  • Add regression coverage for a wall-clock rollback in both resource variants.

Bug

Files.wait_for_processing() and its asynchronous counterpart used time.time() to measure elapsed time. If the system wall clock moves backwards while a file is still processing, the calculated elapsed time also moves backwards and the timeout can be postponed indefinitely.

Reproduction

With max_wait_seconds=1, poll_interval=5, and a wall clock that changes from 100 to 90 after the first poll:

  • Expected: raise the timeout error once the monotonic deadline has elapsed.
  • Actual before this change: continue polling and enter another five-second sleep.

Root cause

Wall-clock time is adjustable and is not suitable for measuring elapsed durations.

Fix

Use Python's monotonic clock for both the initial timestamp and every deadline check. This does not change the public API, poll interval, terminal states, or error message.

Validation

  • tests/lib/test_file_processing.py: 15 passed
  • Ruff check: passed
  • Ruff format check: passed
  • Isolated synchronous and asynchronous rollback reproducer: passed

Commands used:

PYTHONPATH=/tmp/openai-python-file-timeout-deps-20260828:src python -m pytest -p no:cacheprovider -o addopts= --confcutdir=tests/lib --asyncio-mode=auto -q tests/lib/test_file_processing.py
python -m ruff check --no-cache src/openai/lib/_files.py tests/lib/test_file_processing.py
python -m ruff format --no-cache --check src/openai/lib/_files.py tests/lib/test_file_processing.py

@Hughhhhcoder
Hughhhhcoder requested a review from a team as a code owner August 27, 2026 16:12
@Hughhhhcoder

Copy link
Copy Markdown
Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Can't wait for the next one!

Reviewed commit: 23371b4317

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector

Copy link
Copy Markdown

Security review completed. No security issues were found in this pull request.

Reviewed commit: 23371b4317

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

@CAOShurong CAOShurong left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I independently checked the current head 23371b431778b92742b32fc2fec957f7aabee65. On Windows with CPython 3.10, the locked focused file-processing suite passed all 15 tests; Ruff check and format checks passed for both changed files. The sync and async paths both use time.monotonic() consistently, and the regression covers a wall-clock rollback without changing the public timeout API. I found no blocking issue in this focused scope. The full repository CI and matrix remain the appropriate merge gate.

@CAOShurong

Copy link
Copy Markdown

Correction: my preceding review contained a typo in the displayed head SHA. The exact head is 23371b4; the review and local checks were run against that commit.

@CAOShurong CAOShurong left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed exact head 23371b4317. The switch from the wall clock to time.monotonic() is the right timeout primitive here, and the parameterized regression exercises both the synchronous and asynchronous helpers under a simulated wall-clock rollback.

Local focused validation on Windows CPython 3.10:

tests/lib/test_file_processing.py: 15 passed
ruff check: passed
ruff format --check: passed

I also verified that both changed file blobs match this exact commit. GitHub currently reports no public check runs for the PR, so this approval is based on the focused local validation above; the repository's required CODEOWNER review remains a separate gate.

Disclosure: I used AI assistance for diff inspection and local test execution; the exact-head checks and results above were independently reviewed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants